import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Response } from '@angular/http';
import { TreeNode } from 'primeng/primeng';
import { map } from "rxjs/operators";

@Injectable()
export class FormAuthorityService {

    constructor(private http: HttpClient) { }

    /** 获取业务流程树 */
    loadBizProcTree() {
        return this.http.get('/form/api/freeflow/listbizproctree?bizId=0').pipe(
            map((res: Response) => res['data'])
        );
    }

    /**获取流程对应的环节、参与者树 */
    loadActParts(procDefId: number) {
        return this.http.get('/form/api/freeflow/loadactpartstree?procDefId='+ procDefId).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**获取流程对应的表单字段信息 */
    loadProcFormFileds(procDefId: number) {
        return this.http.get('/form/api/authority/listforms?procDefId=' + procDefId).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**获取表单字段权限列表 */
    loadFormFieldAuth(actDefId: number, partId: number) {
        return this.http.get('/form/api/authority/loadauths?actDefId='+actDefId+"&partId="+partId).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**保存文书权限相关信息 */
    saveAythority(auths: any, actDefId: number, partId: number) {
        return this.http.post('/form/api/authority/saveauths?actDefId=' + actDefId + '&partId=' + partId, auths).pipe(
            map((res: Response) => res['data'])
        );
    }
}